package com.tsmti.webservice.util;

import com.alibaba.fastjson.JSON;
import com.tsmti.webservice.constants.RedisConstants;
import com.tsmti.webservice.entity.ServiceInfo;
import com.tsmti.webservice.exception.ErrorCodeEnums;
import com.tsmti.webservice.exception.WebServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @Package：com.tsmti.webservice.util
 * @Class：ServiceInfoUtils
 * @Description： TODO
 * @Author：zcw
 * @Date：Created in 2018/7/24 10:10
 * @Company:
 * @Version：
 * @Modified By:
 */
public class ServiceInfoUtils {
    private static Logger logger = LoggerFactory.getLogger(ServiceInfoUtils.class);
    public static ServiceInfo getService(String tranId,String orgId){
        try {
            List<ServiceInfo> list = JSON.parseArray((String) RedisUtils.getObject(RedisConstants.SERVICEINFO_CACHE),ServiceInfo.class);
            if(list != null && list.size() >0){
                for (ServiceInfo serviceInfo:list){
                    if (tranId.equals(serviceInfo.getTranId()) && orgId.equals(serviceInfo.getOrgId())){
                        return serviceInfo;
                    }
                }
            }
        }catch (Exception e){
            throw new WebServiceException(ErrorCodeEnums.ERROR_SYSTEM.getErrorCode(),e.getMessage());
        }
        return null;
    }
}
